package com.zfei.gfb.query;

import com.zfei.gfb.bean.Const;
import com.zfei.gfb.bean.Page;
import com.zfei.gfb.bean.Status;
import com.zfei.gfb.bean.StatusException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author fgh
 */
@Api("房屋列表-房屋列表")
public class GfbHouseQuery extends Page {

    @ApiModelProperty("最低租金")
    private Integer minPrice;
    @ApiModelProperty("最高租金")
    private Integer maxPrice;

    @ApiModelProperty("是否认证，0:认证中 1:已认证 2:未通过")
    private Integer status;

    @ApiModelProperty("请输入村落/地址")
    private String address;

    @ApiModelProperty("出租方式")
    private Integer type;

    @ApiModelProperty("户型")
    private Integer unit;

    @ApiModelProperty(hidden = true)
    private Integer userId;

    public Integer getUserId() {
        return userId;
    }

    public Integer getUnit() {
        return unit;
    }

    public void setUnit(Integer unit) {
        this.unit = unit;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Integer getMinPrice() {
        return minPrice;
    }

    public void setMinPrice(Integer minPrice) {
        this.minPrice = minPrice;
    }

    public Integer getMaxPrice() {
        return maxPrice;
    }

    public void setMaxPrice(Integer maxPrice) {
        this.maxPrice = maxPrice;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Page check() {
        if (minPrice != null) {
            if (minPrice <= 0 || minPrice >= Integer.MAX_VALUE) {
                throw new StatusException(Status.INVALID_ARGUMENT);
            }
        }
        if (maxPrice != null) {
            if (maxPrice <= 0 || maxPrice >= Integer.MAX_VALUE) {
                throw new StatusException(Status.INVALID_ARGUMENT);
            }
        }
        if (minPrice != null && maxPrice != null) {
            if (maxPrice < minPrice) {
                throw new StatusException(Status.INVALID_ARGUMENT);
            }
        }
        if (status != null && status != Const.HOUSE_STATUS_ING && status != Const.HOUSE_STATUS_ON && status != Const.HOUSE_STATUS_OFF) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        if(unit != null && unit < 0){
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        if(type != null){
            if(type != Const.SHORT_RENTALS && type != Const.LONG_RENTALS){
                throw new StatusException(Status.INVALID_ARGUMENT);
            }
        }
        return this;
    }

    public static boolean checkAllStatus(Integer status) {
        if (status == null) {
            return false;
        }
        if (status != Const.HOUSE_STATUS_ING && status != Const.HOUSE_STATUS_ON && status != Const.HOUSE_STATUS_OFF) {
            return false;
        }
        return true;
    }

    public static boolean checkWebStatus(Integer status) {
        if (status == null) {
            return false;
        }
        if (status != Const.HOUSE_STATUS_ON && status != Const.HOUSE_STATUS_OFF) {
            return false;
        }
        return true;
    }

}

